<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面</title>
    <script src="./js/jquery.js" type="text/javascript"></script>
</head>
<style>
    #dialog{
        width:300px;
        height:50px;
        line-height: 50px;
        padding: 50% 0px;
        background: gray;
        opacity: 0.8;
        position: absolute;
        left:50%;
        top:50%;
        visibility: hidden;
    }
</style>
<body>
<div id="dialog">

</div>

<div id="container" style="width:500px">

    <div id="header" style="background-color:#FFA500;">
        <h1 style="margin-bottom:0;">忘忧商城后台管理页面</h1>
        <h2 id="username">用户名</h2>
    </div>

    <div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
        后台查询出来的
    </div>

    <div id="content" style="background-color:#EEEEEE;height:200px;width:400px;float:left;">
        用来做数据展示的区域
    </div>

    <div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
        版权 © runoob.com
    </div>

</div>

<script>

    //当页面加载完成以后 就自动发起ajax

    //js 对象
    // document.getElementsByTagName()
    //
    // //get 会把jquery对象转换成为 js
    // $(document).get(0)

    //jquery对象  document加载完成以后
    $(document).ready(function () {
        //ajax 把 header token 令牌  用来查询用户信息

        let token = localStorage.getItem("token")

        $.ajax({
            method: "get",
            url: "http://localhost:7000/ums/menu/umsMenu/showMenuByAdminId",
            headers: {"token": token},
            success: function (data) {
                console.log(data)
            }
        });

        $.ajax({
            method: "post",
            url: "/usercenter/admin/getUserInfo",
            headers: {"token": token},
            success: function (data) {
                console.log(data);
                if (data.code === 200) {
                    $("#username").text("欢迎" + data.data.userName + "登陆");

                    //vuex pinia 统一存储了
                    sessionStorage.setItem("userinfo", data.data);

                } else if (data.code === 502) {
                    $("#dialog").show(function () {
                        $("#dialog").text(data.msg);
                        setTimeout(function () {
                            location.href = "./login.html";
                        }, 3000)
                    });
                } else {
                    $("#dialog").show(function () {
                        $("#dialog").text(data.msg);
                    });
                    setTimeout(function () {
                        location.href = "./error.html";
                    }, 3000)
                }
            }
        });
    });


    // ajax 把token 用来取当前用户的 菜单
    treejson = [
        {
            id:1,
            title:"系统管理",
            icon:'',
            children:[
                {
                    id:2,title:'用户管理'
                },
                {
                    id:3,title:'角色管理'
                },
                {
                    id:4,title:'菜单管理'
                }
            ]
        },{
            id:9,
            title: "商品管理",
            children:[
                {}
            ]
        }
    ];


</script>

</body>
</html>